package org.gw.ylc.base.ctrl;

import org.gw.ylc.base.context.RequestContextHolder;
import org.gw.ylc.base.repositories.TeacherRepository;
import org.gw.ylc.base.util.PermissionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("teacher")
public class TeacherCtrl {
	@Autowired
	private TeacherRepository teacherRepository;

	@RequestMapping("query")
	@ResponseBody
	public Object query(String name, String gh) {
		if (StringUtils.hasText(name)) {
			name = "%" + name + "%";
		}
		if (StringUtils.hasText(gh)) {
			gh = "%" + gh + "%";
		}
		return teacherRepository.query(name, gh, PermissionUtil.getFilteredDepartmentId(null),
				RequestContextHolder.get().getPageRequest());
	}
}
